using Cysharp.Threading.Tasks;
using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;
using System;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay
{
    /// <summary>
    /// 关卡常驻资源
    /// </summary>
    public class LevelPermanentResource : IDisposable
    {
        public ResLoader resloader { private set; get; }

        /// <summary>
        /// 头顶指示器
        /// </summary>
        public GameObject prefabHeadIndicator { private set; get; }

        public LevelPermanentResource()
        {
            resloader = ResLoader.Create();
        }

        public async UniTask LoadResource()
        {

            // 加载区
            var taskHeadIndicator = resloader.LoadABAssetAwait<GameObject>(PathConstant.GetEffectPrefabPath("common_effect/Fx_HeadGem"));

            // var nextTask = resloader.LoadABAssetAwait<xx>(xxx);

            // 等待完成区---------------------------------------
            // (请在上面统一去调用加载,然后在下面统一调用await等待加载,这样这些加载是并行加载,加载效率最高)
            // 不要加载一个资源就立即await,这样必须要等待一个完成才能加载下一个,加载效率很低
            prefabHeadIndicator = await taskHeadIndicator;

            // nextPrefab = await nextTask;
        }

        public void Dispose()
        {
            if (resloader != null)
            {
                resloader.Put2Pool();
                resloader = null;
            }
        }
    }
}
